/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} A
 * @param {TreeNode} B
 * @return {boolean}
 */
 var isSubStructure = function(A, B) {
    const isSame = function(A,B){
       if(!B) return true
       if(!A) return false
       if(A.val!==B.val) return false
       return isSame(A.left,B.left)&&isSame(A.right,B.right)
   }
   if(!A||!B) return false
   return isSame(A,B)||isSubStructure(A.left,B)||isSubStructure(A.right,B)
  
};

//本质是中序遍历
//1. 两个中序遍历，两个递归，第一个递归负责找到B根节点与A节点相同的位置，isSame 则负责比较B的左右子树与A是否相同